package org.mall.modules.product.entities;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.mall.common.util.jsonschema.Long2StringSerializer;
import org.mall.common.util.jsonschema.String2LongDeserialize;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @Description: 商品SPU
 * @Author: jeecg-boot
 * @Date:   2019-11-22
 * @Version: V1.0
 */
@Data
@TableName("product_spu")
public class CommoditySpu implements Serializable {
    private static final long serialVersionUID = 1L;

    /**状态(true上架，false下架)*/
    private Boolean visible;
    /**品牌ID*/
    private String brandId;
    /**副标题*/
    private String caption;
    /**类目*/
    private String categoryId;
    /**类目名称*/
    private String categoryName;
    /**分类编号*/
    private Integer cid;
    /**创建时间*/
    private Date createTime;
    /**默认SKU*/
    private Long defaultItemId;
    /**是否删除*/
    private Boolean deleted;
    /**描述*/
    private String description;
    /**SPU 编号*/
    @TableId(type = IdType.INPUT)
    private Long id;

    private String isEnableSpec;
    /**SPU 名字*/
    private String name;
    /**商品主图地址
     *
     * 数组，以逗号分隔
     *
     * 建议尺寸：800*800像素，你可以拖拽图片调整顺序，最多上传15张1*/
    private String picUrls;
    /**原价*/
    private Integer price;

    /**现价*/
    private Integer presentPrice;

    /**库存数量*/
    private Integer quantity;
    /**卖点*/
    private String sellPoint;
    /**商家ID*/
    private String sellerId;
    /**店铺_id*/
    private String shopId;
    /**排序字段*/
    private Integer sort;
    /**模板类型ID（待用）*/
    private String templateTypeId;
    /**审核（0：待审核。1审核通过）*/
    private String toExamine;
    /**最后更新时间*/
    private Date updateTime;

	@TableField(exist = false)
    private List<CommoditySku> productSkuList;

	@TableField(exist = false)
    private Integer salesVolume;

    public Integer getSalesVolume() {
        if (productSkuList!=null){
            return productSkuList.stream().mapToInt(CommoditySku::getSalesVolume).sum();
        }
        return salesVolume;
    }


}
